// pages/search/index.js

import {request} from '../../request/index.js'
import regeneratorRuntime from '../../lib/runtime/runtime.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [],
    // 取消按钮是否隐藏
    isFocus: false,
    value: ''
  },
  TimeId: -1,
handleInput: function (e) {
    let value = e.detail.value
    if (!value.trim()) {
      this.setData({
        goodsList: [],
        isFocus: false
      })
      return 
    }
    // 在查询之前一直在删除这个定时器
    clearTimeout(this.TimeId)
    this.TimeId = setTimeout(() => {
      
      this.setData({
        isFocus: true,
        value
      })
      this.qSearch(this.data.value)
    }, 1000)
  },
  handleQuXiao: function () {
    this.setData({
      isFocus: false,
      value: ''
    })
  },

async qSearch (query) {
  const res = await request({
    url: '/goods/search',
    data: {query}
  })
  console.log(res.data.message.goods)
  this.setData({
    goodsList: res.data.message.goods
  })
}

  
})